package com.wangcang.widgetlibrary.activity;

import android.app.Dialog;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;

import com.wangcang.widgetlibrary.R;
import com.wangcang.widgetlibrary.dialog.DialogTools;

/**
 * 自定义Dialog提示框
 * Created by ShineF on 2017/6/19 0019.
 */

public class DialogActivity extends AppCompatActivity implements DialogTools.ConfirmListener {

    private ListView mLvDialogStyle = null;
    private String[] mStr = new String[]{"提示框", "警告框", "输入框"};

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_dialog);
        init();
    }

    public void init() {
        mLvDialogStyle = (ListView) findViewById(R.id.lv_dialog_style);
        initData();
    }

    public void initData() {
        ArrayAdapter<String> adapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, mStr);
        mLvDialogStyle.setAdapter(adapter);
        mLvDialogStyle.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                operationPosition(position);
            }
        });
    }

    public void operationPosition(int position) {
        switch (position) {
            case 0:
                DialogTools.getInstance().showCustomDialogPrompt(this, "提示", "我是内容", false, this);
                break;
            case 1:
                DialogTools.getInstance().showCustomWarning(this, "警告", "你家着火了", false, null);
                break;
            case 2:
                DialogTools.getInstance().showCustomInput(this, "选择输入", false, this);
                break;
        }
    }

    @Override
    public void setConfirmListener(Dialog dialog, View view, String input) {
        String s;
        if (TextUtils.isEmpty(input)) {
            s = "确定";
        } else {
            s = input;
        }
        Toast.makeText(this, s, Toast.LENGTH_SHORT).show();
        dialog.dismiss();
    }
}
